package com.zl.smartmall.library.im.po;

import org.json.JSONException;
import org.json.JSONObject;

import com.zl.smartmall.library.util.Constants;

import android.text.TextUtils;

public class PushMessageInfo {

	// i:24 # 该通知对应的msgid
	// m:18 # pmid
	// d:1234567891 # 该消息产生的时间戳
	// u:200 # 发送这条通知的人的uid
	// n:"昵称" # 昵称
	// g:0 # 性别
	// f:"http" # 头像地址
	// c:"私信内容" # 私信内容，全文
	// p:"http://XXX" # 图片地址
	// l:23 # 上一条私信的msgid，亦既是lastid，若没有就是0, <================ look at me!
	private int msgId;
	private int chatId;
	private long time;
	private int lastId;
	private int msgType;
	private int senderUid;
	private int senderGender;
	private String senderFace;
	private String message;
	private String pictureUrl;
	private String senderNickname;

	public int getMsgId() {
		return msgId;
	}

	public void setMsgId(int msgId) {
		this.msgId = msgId;
	}

	public int getChatId() {
		return chatId;
	}

	public void setChatId(int chatId) {
		this.chatId = chatId;
	}

	public long getTime() {
		return time;
	}

	public void setTime(long time) {
		this.time = time;
	}

	public int getLastId() {
		return lastId;
	}

	public void setLastId(int lastId) {
		this.lastId = lastId;
	}

	public int getMsgType() {
		return msgType;
	}

	public void setMsgType(int msgType) {
		this.msgType = msgType;
	}

	public int getSenderUid() {
		return senderUid;
	}

	public void setSenderUid(int senderUid) {
		this.senderUid = senderUid;
	}

	public int getSenderGender() {
		return senderGender;
	}

	public void setSenderGender(int senderGender) {
		this.senderGender = senderGender;
	}

	public String getSenderFace() {
		return senderFace;
	}

	public void setSenderFace(String senderFace) {
		this.senderFace = senderFace;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getPictureUrl() {
		return pictureUrl;
	}

	public void setPictureUrl(String pictureUrl) {
		this.pictureUrl = pictureUrl;
	}

	public String getSenderNickname() {
		return senderNickname;
	}

	public void setSenderNickname(String senderNickname) {
		this.senderNickname = senderNickname;
	}

	public static PushMessageInfo parse(JSONObject jsonObject) throws JSONException {
		PushMessageInfo pushMessageInfo = null;
		if(jsonObject != null && jsonObject.length() > 0) {
			pushMessageInfo =  new PushMessageInfo();
			pushMessageInfo.chatId = jsonObject.getInt("m");
			pushMessageInfo.lastId = jsonObject.getInt("l");
			pushMessageInfo.message = jsonObject.getString("c");
			pushMessageInfo.msgId = jsonObject.getInt("i");
			pushMessageInfo.pictureUrl = jsonObject.getString("p");
			pushMessageInfo.senderFace = jsonObject.getString("f");
			pushMessageInfo.senderGender = jsonObject.getInt("g");
			pushMessageInfo.senderNickname = jsonObject.getString("n");
			pushMessageInfo.senderUid = jsonObject.getInt("u");
			pushMessageInfo.time = jsonObject.getLong("d");
			if(TextUtils.isEmpty(pushMessageInfo.pictureUrl)) {
				pushMessageInfo.setMsgType(Constants.CHAT_MSG_TYPE_CHARACTERS);
			}else {
				pushMessageInfo.setMsgType(Constants.CHAT_MSG_TYPE_PICTURE);
			}
		}
		return pushMessageInfo;
	}
	
}
